package com.hh.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import java.io.IOException;

@Configuration
public class Config {
    
    
    @Bean
    public FilterRegistrationBean regFilter() {
        FilterRegistrationBean userFilter = new FilterRegistrationBean();
        userFilter.addUrlPatterns("/*");
        userFilter.setFilter(new UserFilter());
        return userFilter;
        
    }
    
    public class UserFilter implements Filter {
        
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            if (request.getContentType().contains("hh"))
                response.getWriter().write("怀化 response");
            else chain.doFilter(request, response);
        }
    }
}
